/**
 * Calculator class. Contains basic mathematic operations.
 */
package calc

object Calc {
    def main(args:Array[String]) = {
        println("Sum 3 and 5 is: " + sum(3,5))
        println("Sum of array is: " + sum(Array(3, 5, 6, 8)))
        println("3 * 5 is: " + mul(3,5))
        println("Max of 2 and 5 is: " + max(2,5));
        println("Max of 2 and 5  3 is: " + max(Array(2, 5, 3)));
    }
    
    def sum(a:Int, b:Int): Int = {
        a + b;
    }
    
    def sum(ints: Seq[Int]): Int = {
        ints.foldLeft(0)((a,b) => a + b)
    }
    
    def mul(a:Int, b:Int): Int = {
        a * b;
    }
    
    def max(a:Int, b:Int): Int = {
        if (a > b) a else b;
    }
    
    def max(ints: Seq[Int]) = {
        ints.reduceLeft(_ max _)
        //OR: ints.reduceLeft((a, b) => a max b);
    }
}